package com.demo.admin.service.impl;

import java.util.*;

import org.springframework.stereotype.Service;

import com.demo.admin.domain.result.GetUserInfoResult;
import com.demo.admin.service.SystemService;
import com.demo.admin.util.AdminRequestContext;
import com.demo.common.enums.GatewayAccountType;
import com.demo.common.exception.ErrorEnums;
import com.demo.common.exception.DemoException;

import lombok.extern.slf4j.Slf4j;

/**
 * SystemServiceImpl
 * 
 * @author etiger
 * @data 2022-08-08 09:30:29
 */
@Slf4j
@Service
public class SystemServiceImpl implements SystemService {

    /**
     * 获取网关账号权限信息
     * 
     * @author etiger
     */
    @Override
    public GetUserInfoResult getInfo() {
        Integer gatewayAccountId = AdminRequestContext.getGatewayAccountId();
        if (gatewayAccountId == null) {
            throw new DemoException(ErrorEnums.ILLEGAL_REQUEST);
        }
        String username = AdminRequestContext.getUsername();
        GatewayAccountType gatewayAccountType = AdminRequestContext.getUserType();
        List<String> roles = new ArrayList<>();
        roles.add(gatewayAccountType.getCode());
        GetUserInfoResult getUserInfoResult = new GetUserInfoResult();
        getUserInfoResult.setRoles(roles);
        getUserInfoResult.setIntroduction("I am a " + gatewayAccountType.getName());
        getUserInfoResult.setAvatar("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        getUserInfoResult.setName(username);
        return getUserInfoResult;
    }

}
